package com.jlnk.stockdemo.utils;

import android.content.Context;
import android.widget.Toast;

public class ToastUtils {
    private static Toast toast;
    private static Context mContext;

    public static void init(Context context) {
        mContext = context;
    }

    public static void showToast(String message) {
        if (toast == null) {
            toast = Toast.makeText(mContext, message, Toast.LENGTH_SHORT);
        } else {
            toast.setText(message);
        }
        toast.show();
    }

    public static void showToast(int resId) {
        if (toast == null) {
            toast = Toast.makeText(mContext, mContext.getResources().getText(resId), Toast.LENGTH_SHORT);
        } else {
            toast.setText(resId);
        }
        toast.show();
    }

    public static void cancelToast() {
        if (toast != null) {
            toast.cancel();
        }
    }
}